function searchByState(stateCode){
	//check if the stateCode is valid
	var isValidStateCode = false;
	for(index=0; index < document.StoreFinderForm.StoreFinderForm_State.options.length ; index++) {
		var value = document.StoreFinderForm.StoreFinderForm_State.options[index].value;
		if(value == stateCode){
			isValidStateCode = true;
			break;
		}
	}
	
	if(!isValidStateCode){
		return;
	}else{
		document.StoreFinderForm.StoreFinderForm_State.value = stateCode;
		document.StoreFinderForm.action = document.StoreFinderForm.searchByStateAction.value;
		document.StoreFinderForm.submit();
	}
	
}



( function( $ ){
	
	MC.StoreLocator = function(){	
		return
	};

	MC.StoreLocator = {

			errorMessaging : {

				updateCheck : function(){},
				
				focusCheck : function( input , thisMessagebox , allMessageBoxes ){
					MC.StoreLocator.errorMessaging.updateCheck = setInterval( function( inputVal ){
						if( MC.StoreLocator.errorMessaging.validateZipCode( input.value ) && $(thisMessagebox).hasClass("displayed") ){
							MC.StoreLocator.errorMessaging.message( "hide" , input , thisMessagebox , allMessageBoxes );
						}
					} , 5 )
				},
				
				clearCheck : function(){
					clearInterval( MC.StoreLocator.errorMessaging.updateCheck )
				},
				
				validateZipCode : function( val , callback ){
					var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
				    if ( !zipCodePattern.test( val ) ){
				    	return callback ? callback.apply() : false
				    } else {
				    	return true
				    }
				},
				
				getElements : function( input ){
					
				},
				
				message : function( display , input , ele , eles ){
					
					if( display === "show" ){
						if( !$(ele).hasClass("displayed") ){
							var oldMessage = $(ele).html();
							$(input).addClass("error");
							$(ele).html(  '<span class="message">'+$(ele).attr( "data-type-error-mess" )+'</span><span class="arrow"></span>').attr( "data-type-error-mess" , oldMessage );
							$(ele).fadeIn( 750 );
							$(eles).addClass( $(eles).attr("data-type-alt-class") ).css( { "height" : $(ele).height() })
						};
					} else if( display === "hide" ){
						if( $(ele).hasClass("displayed") ){
							var oldMessage = $(ele).children("span.message").html();
							$(input).removeClass("error");
							$(ele).html("").attr( "data-type-error-mess" , oldMessage );
							$(ele).fadeOut( 175 , function(){});						//$(eles).removeClass( $(eles).attr("data-type-alt-class") ).css( { "height" : "auto" })
							$(eles).css( { "height" : "auto" }).removeClass( $(eles).attr("data-type-alt-class") );
						};
					}
					
				}

				
			}
	};
	
	$(document).ready( function(){

		if( !MC.StoreLocator.errorMessaging.validateZipCode( $("#StoreFinderForm_PostalCode").val() ) && $("#StoreFinderForm_PostalCode").val() > 0 ){
			var input = $("#StoreFinderForm_PostalCode"),
			form = $(input).parent("div").parent("form"),
			thisMessagebox = $(input).parent("div").children("div.error"),
			allMessageBoxes = $(form).children("div").children("div.error");
			MC.StoreLocator.errorMessaging.message( "show" , input , thisMessagebox , allMessageBoxes )
		}

	});
	
	
	$(document).delegate( "#StoreFinderForm_PostalCode" , "focus" , function(){

		var input = this,
			form = $(input).parent("div").parent("form"),
			thisMessagebox = $(input).parent("div").children("div.error"),
			allMessageBoxes = $(form).children("div").children("div.error");

		MC.StoreLocator.errorMessaging.focusCheck( input , thisMessagebox , allMessageBoxes );

	});

	$(document).delegate( "#StoreFinderForm_PostalCode" , "blur" , function(){
		
		MC.StoreLocator.errorMessaging.clearCheck();
		
		var input = this,
			form = $(input).parent("div").parent("form"),
			thisMessagebox = $(input).parent("div").children("div.error"),
			allMessageBoxes = $(form).children("div").children("div.error");

		if( input.value.length > 0 ){
			MC.StoreLocator.errorMessaging.validateZipCode( input.value , function(){
				 MC.StoreLocator.errorMessaging.message( "show" , input , thisMessagebox , allMessageBoxes )
			});			
		} else {
				MC.StoreLocator.errorMessaging.message( "hide" , input , thisMessagebox , allMessageBoxes )
		}

	});

})( jQuery )


